import request from "@/utils/request";
import type { SettlementQuery, SettlementVO, SettlementForm } from "@/types/attendance/settlement";
import type { PageResult } from "@/types/common/response";

/**
 * 获取结算单列表
 */
export const getSettlementList = (query: SettlementQuery) => {
  return request.get<PageResult<SettlementVO>>("/attendance/settlement/list", { params: query });
};

/**
 * 获取结算单详情
 */
export const getSettlement = (id: number) => {
  return request.get<SettlementVO>(`/attendance/settlement/${id}`);
};

/**
 * 新增结算单
 */
export const addSettlement = (data: SettlementForm) => {
  return request.post("/attendance/settlement", data);
};

/**
 * 修改结算单
 */
export const updateSettlement = (data: SettlementForm) => {
  return request.put("/attendance/settlement", data);
};

/**
 * 删除结算单
 */
export const deleteSettlement = (id: number) => {
  return request.delete(`/attendance/settlement/${id}`);
};

/**
 * 导出结算单
 */
export const exportSettlement = (query: SettlementQuery) => {
  return request.download("/attendance/settlement/export", { params: query });
};

/**
 * 计算结算单明细
 */
export const calculateSettlementDetails = (
  projectId: number,
  startDate: string,
  endDate: string
) => {
  return request.get("/attendance/settlement/calculate", {
    params: {
      projectId,
      startDate,
      endDate
    }
  });
};

/**
 * 获取结算单明细列表
 */
export function getSettlementDetails(id: number) {
  return request({
    url: `/attendance/settlement/detail/${id}`,
    method: "get"
  });
}

/**
 * 自动计算结算单明细
 */
export function calculateSettlementDetails(data: SettlementForm) {
  return request({
    url: "/attendance/settlement/calculate",
    method: "post",
    data: data
  });
}
